package com.moon.cloud.common.response;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;

import java.io.Serial;
import java.io.Serializable;

/**
 * 返回格式定义
 */
@Setter
@Getter
@Schema(description = "统一返回")
public class ResponseEntity<T> implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    @JsonProperty("status")
    @Schema(description = "状态")
    private Integer status = 0;

    @JsonProperty("isSuccess")
    @Schema(description = "返回状态")
    private Boolean isSuccess = Boolean.TRUE;

    @JsonProperty("message")
    @Schema(description = "消息体")
    private String message;

    @JsonProperty("timestamp")
    @Schema(description = "时间戳（毫秒）")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private Long timestamp;

    @JsonProperty("data")
    @Schema(description = "数据")
    @JsonInclude(JsonInclude.Include.NON_NULL)
    private T data;

    public ResponseEntity() {
        this.timestamp = System.currentTimeMillis();
    }

    public ResponseEntity(int status, Boolean isSuccess, String message) {
        this();
        this.status = status;
        this.isSuccess = isSuccess;
        this.message = message;
    }

    public ResponseEntity(int status, String message, Boolean isSuccess, T data) {
        this();
        this.status = status;
        this.message = message;
        this.isSuccess = isSuccess;
        this.data = data;
    }

}
